﻿using MyBLL;
using MyEntity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyBLL;
using MyDAL;

namespace MyUI
{
    public partial class FrmAdd : Form
    {
        public FrmAdd()
        {
            InitializeComponent();
        }

        //绑定combox中的数据
        ProfessionInfoBLL professionInfoBLL = new ProfessionInfoBLL();
        StudentInfoDAl dal = new StudentInfoDAl();
        StudentInfoEntity stu = new StudentInfoEntity();

        private void BindPro()
        {
            List<ProfessionInfoEntity> list = new List<ProfessionInfoEntity>();
            list = professionInfoBLL.List();
            list.Insert(0, new ProfessionInfoEntity { ProfessionID = 0, ProfessionName = "请选择" });
            this.cmbName.DataSource = list;
            //显示内容
            this.cmbName.DisplayMember = "ProfessionName";
            //编号
            this.cmbName.ValueMember = "ProfessionID";
        }


        private void button1_Click(object sender, EventArgs e)
        {
            stu.StuID = this.textBox1.Text;
            stu.StuName = this.textBox2.Text;
            stu.StuAge = Convert.ToInt32(this.textBox3.Text);
            string hobby = "";
            foreach (CheckBox item in this.panel2.Controls)
            {
                if (item.Checked)
                {
                    if (!hobby.Equals(""))
                    {
                        hobby += ",";
                    }
                    hobby += item.Text;
                }
            }
            stu.StuHobby = hobby;
            stu.ProfessionID = Convert.ToInt32(this.cmbName.SelectedValue.ToString());
            int count = dal.Add(stu);
            if (count == 1)
            {
                MessageBox.Show("添加成功");
            }
            else
            {
                MessageBox.Show("添加失败");
            }
            this.Close();
        }

        private void FrmAdd_Load(object sender, EventArgs e)
        {
            BindPro();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (this.checkBox1.Checked)
            {

                this.checkBox2.Checked = false;
                stu.StuSex = "男";
            }
            else
            {
                this.checkBox1.Checked = false;
                stu.StuSex = "女";
            }
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (this.checkBox2.Checked)
            {

                this.checkBox1.Checked = false;
                stu.StuSex = "女";

            }
            else
            {
                this.checkBox2.Checked = false;
                stu.StuSex = "男";

            }
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void cmbName_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
